package br.com.massai.model.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.envers.Audited;

@Audited
@Entity
@Table(name = "SERVICE_ITEM")
@NamedQueries({
	@NamedQuery(name = "ServiceItem.find", query = "SELECT s FROM ServiceItem s"),
	@NamedQuery(name = "ServiceItem.duplicate", query = "SELECT COUNT(s) FROM ServiceItem s WHERE s.levelService = :levelService")
})
public class ServiceItem extends GenericEntity {

	private static final long serialVersionUID = -6688064389077939768L;

	@Id
	@SequenceGenerator(name = "seqServiceItem", sequenceName = "seq_service_item", allocationSize = 1)
	@GeneratedValue(generator = "seqServiceItem", strategy = GenerationType.SEQUENCE)
	private Long id;

	@Column(name = "NAME_SERVICE", length = 255, nullable = false, columnDefinition = "VARCHAR(255)")
	private String nameService;

	@Column(name = "LEVEL_SERVICE", precision = 5, scale = 0, nullable = false, columnDefinition = "NUMERIC(5,0)")
	private Integer levelService;

	@ManyToOne(optional = false, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "UNIT_MEASURE_ID", referencedColumnName = "ID")
	private UnitMeasure unitMeasure;
	
	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "CATEGORY_LEVEL_ID", referencedColumnName = "ID")
	private CategoryLevel categoryLevel;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNameService() {
		return nameService;
	}

	public void setNameService(String nameService) {
		this.nameService = nameService;
	}

	public Integer getLevelService() {
		return levelService;
	}

	public void setLevelService(Integer levelService) {
		this.levelService = levelService;
	}

	public UnitMeasure getUnitMeasure() {
		return unitMeasure;
	}

	public void setUnitMeasure(UnitMeasure unitMeasure) {
		this.unitMeasure = unitMeasure;
	}

	public CategoryLevel getCategoryLevel() {
		return categoryLevel;
	}

	public void setCategoryLevel(CategoryLevel categoryLevel) {
		this.categoryLevel = categoryLevel;
	}
}